#pragma once

struct file_t
{
	file_t();
	file_t(const char* filename,const char* mode);
	~file_t();

	bool open(const char* filename, const char* mode);
	void close();
	bool is_open() const{return f!=NULL;}
	uint32 length() const {return size;}


	void read(void* dst, uint32 numbytes);
	void write(const void* str,int len);

	template<typename T> void write(const T& t)
	{
		write(&t,sizeof(T));
	}
	template<typename T> void read(T& t)
	{
		read(&t,sizeof(T));
	}

/*
	void write(int);
	void write(uint32);
	void read(int&);
	void write(float);
	void read(float&);
	void write(bool);
	void read(bool&);
*/

	void write(const stringhash& s)
	{
		write(s.str->size());
		write(s.c_str(),s.str->size()+1);
	}
	void read(stringhash& s)
	{
		char c[1024];
		uint32 size;

		read(size);
		read(c,size+1);
		s=stringhash::get(c);
	}
	void writestring(const char* str);
	void writestring(const string& str);
	FILE* f;
	uint32 size;
};